import { CommonUtil } from './../../../../common/utils/common.util';
import { ActivatedRoute } from '@angular/router';
import { EvaluatingService } from './service/evaluating.service';
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common'

@Component({
    selector: 'estate-evaluating',
    templateUrl: './estate-evaluating.component.html',
    styleUrls: ['./estate-evaluating.component.scss']
})
export class EstateEvaluatingComponent implements OnInit {

    public error:boolean=false;
    public loading:boolean=false;
    public project: any;

    public imgview={
        "show":false,
        "list":[],
        "index":0
    }

    sliderConfig = {
        effect: 'slide',
        autoHeight: true,
        loop: true
      }

    constructor(
        private routeInfo: ActivatedRoute,
        private location: Location,
        private utils: CommonUtil,

        private sevice: EvaluatingService
    ) { }

    ngOnInit() {
        this.project = this.routeInfo.snapshot.queryParams['project'];
        this.evaluatingService();

    }
    onClickLeft(){
        this.location.back()
    }

    handleReload() {
        this.error = false
        this.loading = true
        // this.getDetail(this.promotion)
      }

    handleClose(){
        // this.imgview.show=false;
        this.location.back()
    }

    //api
    evaluatingService() {
        let req = {
            "pager": { "Start": 0, "Limit": 0 },
            "filter": {
                "Lambda": "item=>item.Project==" + this.project + "&&item.CategoryInfo.Code ==\"ArtcleCategory_Evaluation\"",
                "Navigations": [], "Latitude": 28.692499, "Longitude": 115.815292
            },
            "sorters": [{ "Property": "item=>item.Sort", "Direction": "Ascending" },
            { "Property": "item=>item.UpdateTime", "Direction": "Descending" }]
        }
        this.loading=true;
        this.sevice.getEvaluatingDetail(req, res => {

            this.error = false;
            this.loading = false;
            this.imgview.show = true;

            if(res.Result&&res.Success){

                let items = res.Result.Value;
                console.log(items);
                items.forEach(element => {
                    element.Photo = this.utils.getPhotoByName(element.Photo, '楼盘评测')[0];
                    element.Desc =element.Description;
                });

                this.imgview.list = items;
                
            }

        },error=>{
            this.error = true;
        });
    }
}
